package ua.net.gm.common.entity;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

/**
 *
 * @author Yason
 */
class EntityIdFactory
{
    private final Map<EntityType, AtomicInteger> counters;
    
    EntityIdFactory()
    {
        counters = new HashMap<>();
    }
    
    public synchronized int createId(EntityType type)
    {
        AtomicInteger counter = counters.get(type);
        if (counter == null)
        {
            counter = new AtomicInteger();
            counters.put(type, counter);
        }
        return counter.getAndIncrement();
    }
}
